<%@ page import="com.hdu.heihei.service.impl.UserServiceImpl" %>
<%@ page import="com.hdu.heihei.beans.User" %>
<%@ page import="com.hdu.heihei.service.impl.UserServiceImpl" %>
<%@ page import="com.hdu.heihei.beans.User" %><%--
  Created by IntelliJ IDEA.
  User: fengyuan
  Date: 2020/9/29
  Time: 01:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>更新</title>
</head>
<body>
<%
    UserServiceImpl userServiceImpl = new UserServiceImpl();

    User user = new User();
    user.setId(Integer.parseInt(request.getParameter("id")));
    user.setUsername(request.getParameter("username"));
    user.setPassword(request.getParameter("password"));

    if(userServiceImpl.update(user)){
        Cookie cookieId = new Cookie("userId",String.valueOf(user.getId()));
        Cookie cookieUsername = new Cookie("username", user.getUsername());
        Cookie cookiePassword = new Cookie("password", user.getPassword());
        cookieId.setMaxAge(-1);
        cookieUsername.setMaxAge(-1);
        cookiePassword.setMaxAge(-1);
        cookieId.setPath(request.getContextPath());
        cookieUsername.setPath(request.getContextPath());
        cookiePassword.setPath(request.getContextPath());
        response.addCookie(cookieId);
        response.addCookie(cookieUsername);
        response.addCookie(cookiePassword);
        out.print("<script language='javaScript'> alert('修改信息成功');</script>");
    }else {
        out.print("<script language='javaScript'> alert('修改信息失败');</script>");
    }
    response.setHeader("refresh", "0;url=../views/edit.jsp");
%>
</body>
</html>
